import InteractiveBase from "../../../LevelCommon/InteractiveBase";
import { utils } from "../../../../utils/CommonUtil";

export default class PhysPassLock extends InteractiveBase {

    /** 正确的密码索引*/
    public correctPassInde: Array<number> = new Array<number>();

    public ChildPassKeyCurIndex:Array<number> = new Array<number>();
    /** 是否都对了*/
    public isCorrect: boolean = false;
    /** 是否在正确后销毁*/
    public isDestroyEnd: boolean = false;

    private mowner: Laya.Sprite3D;

    onStart() {
        this.mowner = this.owner as Laya.Sprite3D;
        this.InitComponent();
    }

    private InitComponent() {
        for (let index = 0; index < this.correctPassInde.length; index++) {
            this.ChildPassKeyCurIndex.push(0);
        }
        let coolider = this.mowner.getComponent(Laya.PhysicsCollider) as Laya.PhysicsCollider;
        if(coolider != null){
            coolider.enabled = false;
        }
    }

    /** 检测密码*/
    public CheckPassWord(): boolean {
        for (let i = 0; i < this.correctPassInde.length; i++) {
            /** 有密码不对*/
            if (this.ChildPassKeyCurIndex[i] != this.correctPassInde[i]) {
                return false;
            }
        }
        this.isCorrect = true;
        if (this.isDestroyEnd) {
            this.mowner.destroy();
        }
        console.log("密码正确！！！！！！！！！");
        this.CallToLevel(this.mowner.name + "_UnLock");
        return true;
    }
}